/*
 *  Copyright 2010 UPF Telecos 4th group G.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package edu.upf.messages;

import edu.upf.utils.Definitions;
import org.jivesoftware.smack.packet.Message;

/**
 * Class that implements a generic message for requests and responses between
 * clients
 * @author netjois
 */
public class GenericMessage implements Definitions {

    private Object payload;
    private String to;
    private String from;

    /**
     * Constructor, receives the source, destination and payload to send
     * @param from
     * @param to
     * @param payload
     */
    public GenericMessage(String from, String to, Object payload){

        this.from=from;
        this.to=to;
        this.payload=payload;
    }

    /**
     * Gets the payload of the message
     * @return
     */
    public Object getObject() {
        return payload;
    }

    /**
     * Sets the payload of the message
     * @param payload
     * @return
     */
    public boolean setObject(Object payload) {
        this.payload=payload;
        return true;
    }

    /**
     * Gets the XMPP message to sending through a XMPP connection
     * @return
     */
    public Message getMessage(){
        Message msg=new Message(to,Message.Type.normal);
        msg.setProperty(PAYLOAD, payload);
        return msg;
    }

    /**
     * Returns the origin adress of the message
     * @return
     */
    public String getFrom(){
        return from;
    }
}
